package com.weakteam.androidclient.app.menu;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.weakteam.androidclient.data.domain.Menu;
import com.weakteam.androidclient.util.MainProperties;

import java.io.File;

/**
 * @author Nail
 */
public class MenuButton extends LinearLayout {

    private Context context;
    private TextView title;
    private ImageButton button;

    public MenuButton(Context context) {
        super(context);
        this.context = context;

        this.button = new ImageButton(this.context);
        this.addView(button);

        this.title = new TextView(this.context);
        this.title.setTextColor(Color.rgb(0, 0, 0));
        this.title.setTextSize(10);
        this.title.setBackgroundColor(Color.rgb(1, 0, 0));
        this.addView(title);
    }

    public void setMenu(Menu menu) {
        this.title.setText(menu.getName());
        File imageFolderPath = MainProperties.getInstance().getPicturesFolder(this.context);
        File imgFile = new File(imageFolderPath, menu.getImage());
        Bitmap bitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
        this.button.setImageBitmap(bitmap);
    }

    public void setSize(float width) {
        ViewGroup.LayoutParams params = this.button.getLayoutParams();
        params.height = (int)width;
        params.width = (int)width;
        button.setLayoutParams(params);

        float titleHeight = 10.0f;

        ViewGroup.LayoutParams titleParams = button.getLayoutParams();
        titleParams.height = (int)titleHeight;
        titleParams.width = (int)width;
        this.title.setLayoutParams(titleParams);
    }

}
